using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace MyMedia.iPod.Music
{
	public class Playlist : Node
	{
		Mhyp m_mhyp;
		string m_name;

		//protected override int Size
		//{
		//    get { return m_mhyp.HeaderLength; }
		//}

		protected override void ReadImpl(BinaryReader reader)
		{
			m_mhyp = new Mhyp();
			m_mhyp.Read(reader);

			for (int j = 0; j < m_mhyp.DataObjectChildCount; j++)
			{
				DataObject dataObj = new DataObject();
				AddChild(dataObj);
				dataObj.Read(reader);

				if (dataObj.Type == 1)
				{
					DataString dataString = new DataString();
					dataObj.AddChild(dataString);
					dataString.Read(reader);

					m_name = dataString.Value;
				}
				else
				{
					DataBlob dataBlob = new DataBlob();
					dataObj.AddChild(dataBlob);
					dataBlob.Read(reader);
				}
			}

			for (int j = 0; j < m_mhyp.PlaylistItemCount; j++)
			{
				PlaylistItem item = new PlaylistItem();
				AddChild(item);
				item.Read(reader);					
			}
		}

		protected override void WriteImpl(BinaryWriter writer)
		{
			m_mhyp.Write(writer);
		}

		protected override void SetSize(int size)
		{
			m_mhyp.TotalLength = size;
		}

		public string Name
		{
			get { return m_name; }
		}
	}
}
